

public class Sort{
    public static void selectSort(int[] array) {
        for (int i = 0; i < array.length;i++) {

            int minIndex = i;
            for (int j = i+1;j < array.length;j++) {
                if (array[minIndex] > array[j] ) {
                    minIndex = j;
                }
            }
            int temp = array[i];
            array[i] = array[minIndex];
            array[minIndex] = temp;
        }
    }
    public static void selectSort2(int[] array) {
        int left = 0;
        int right = array.length-1;
        while (left < right) {
            //i  minIndex   maxIndex
            int minIndex = left;
            int maxIndex = right;
            for (int i = left + 1;i <= right ;i++) {
                if (array[minIndex] > array[i]) {
                    minIndex = i;
                }
                if (array[maxIndex] < array[i]) {
                    maxIndex = i;
                }
            }
            int temp1 = array[minIndex];
            array[minIndex] = array[left];
            array[left] = temp1;
            left++;

            int temp2 = array[maxIndex];
            array[maxIndex] = array[right];
            array[right] = temp2;
            right++;

        }
    }
}